﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Configuration.Provider;
using System.Data.SqlClient;

namespace _114sct
{
    public partial class sctmanage : System.Web.UI.Page
    {
        private DataSet data;
        private string connectionString;
        private SqlDataAdapter adapter;

       

        protected void Page_Load(object sender, EventArgs e)
        {
            ConnectionStringSettings ConnectionStringSettings =
                     ConfigurationManager.ConnectionStrings["cj"];

            if (ConnectionStringSettings == null || ConnectionStringSettings.ConnectionString.Trim() == "")
            {
                throw new ProviderException("Connection string cannot be blank.");
            }

            connectionString = ConnectionStringSettings.ConnectionString;
            
                

        }
        
        protected void BrandManage(object sender, EventArgs e)
        {
           
            SqlConnection conn = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("select * from [dbo].[114sct_brand]", conn);
            adapter = new SqlDataAdapter(cmd);
            data = new DataSet();
            try
            {
                conn.Open();
                adapter.Fill(data, "114sct_brand");
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            datagrid.Columns.Clear();
            datagrid.DataSource = data;
            TemplateField check = new TemplateField();
            check.ItemTemplate = new GridViewTemplate_CheckBox();
            check.ItemStyle.Width = new Unit(20, UnitType.Pixel);
            //check.ControlStyle.Width = new Unit(5, UnitType.Pixel);
            datagrid.Columns.Add(check);
            BoundField id = new BoundField();
            id.DataField = "id";
            id.HeaderText = "ID";
            id.ReadOnly = true;
            id.SortExpression = "id";
            id.ItemStyle.Width = new Unit(30, UnitType.Pixel);
            //id.ControlStyle.Width = new Unit(30, UnitType.Pixel);
            datagrid.Columns.Add(id);
            BoundField brandurl = new BoundField();
            brandurl.DataField = "brandUrl";
            brandurl.HeaderText = "网址";
            brandurl.ReadOnly = true;
            brandurl.SortExpression = "brandUrl";
            brandurl.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            //brandurl.ControlStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(brandurl);
            BoundField brandname = new BoundField();
            brandname.DataField = "brandName";
            brandname.HeaderText = "名称";
            brandname.ReadOnly = true;
            brandname.SortExpression = "brandName";
            brandname.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(brandname);
            BoundField contact = new BoundField();
            contact.DataField = "contact";
            contact.HeaderText = "联系方式";
            contact.ReadOnly = true;
            contact.SortExpression = "contact";
            contact.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(contact);
            BoundField category = new BoundField();
            category.DataField = "category";
            category.HeaderText = "分类";
            category.ReadOnly = true;
            category.SortExpression = "category";
            category.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(category);
            BoundField keyword = new BoundField();
            keyword.DataField = "keyword";
            keyword.HeaderText = "关键词";
            keyword.ReadOnly = true;
            keyword.SortExpression = "keyword";
            keyword.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(keyword);
            BoundField other = new BoundField();
            other.DataField = "other";
            other.HeaderText = "其它";
            other.ReadOnly = true;
            other.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(other);
            BoundField credentials = new BoundField();
            credentials.DataField = "credentials";
            credentials.Visible = false;
            datagrid.Columns.Add(credentials);
            TemplateField credentialsimage = new TemplateField();
            credentialsimage.ItemTemplate = new GridViewTemplate_ImageLink();
            credentialsimage.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(credentialsimage);
            datagrid.DataKeyNames = new string[] { "id" };
            datagrid.RowDataBound += BrandManage_RowDataBound;
            datagrid.DataBind();
            delbrandbtn.Visible = true;
            string str = "";
            for (int i = 0; i < datagrid.Rows.Count; i++)
            {
                str += "checkedlist[" + i.ToString() + "]='" + datagrid.Rows[i].Cells[0].Controls[0].ID.ToString() + "';";
            }
            ClientScript.RegisterStartupScript(this.GetType(), "init", "<script>var checkedlist=new Array();" + str + "delconfirm=undefined;</script>");
            ClientScript.RegisterOnSubmitStatement(this.GetType(), "onsubmit", "if(delconfirm==false){return false;};" +
                                                                                "for(var i=0;i<checkedlist.length;i++)" +
                                                                                "{if(document.getElementById(checkedlist[i]).checked==true) document.getElementById('checkedlist').value+=(checkedlist[i]+'|')}");
            delbrandbtn.OnClientClick = "javascript:var r=confirm('确实要删除吗？');if(r==true){delconfirm=true;}else{delconfirm=false;}";
        }

        protected void DelBrand(object sender, EventArgs e)
        {
            string checkedlist = Request.Params["checkedlist"];
            if (checkedlist == "")
            {
                ClientScript.RegisterStartupScript(this.GetType(), "delerror", "<script>alert('删除前请选择')</script>");
                BrandManage(null, EventArgs.Empty);
                return;
            }
            char[] charSeparators = new char[] { '|' };
            string[] brands = checkedlist.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
            SqlConnection conn = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("delete from [114sct_brand] where [id]=@id", conn);
            cmd.Parameters.Add("@id", SqlDbType.Int);
            try
            {
                conn.Open();
                foreach (string brand in brands)
                {
                    cmd.Parameters["@id"].Value = Convert.ToInt32(brand);
                    cmd.ExecuteNonQuery();
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            BrandManage(null, EventArgs.Empty);
        }
        private void BrandManage_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string url=((DataRowView)e.Row.DataItem)["credentials"].ToString();
                ((HyperLink)e.Row.Cells[9].Controls[0]).NavigateUrl =string.IsNullOrEmpty(url)?"#":"uploads/"+url;
                ((CheckBox)e.Row.Cells[0].Controls[0]).ID = ((DataRowView)e.Row.DataItem)["id"].ToString();
            }
        }

        protected void FaultManage(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("select * from [dbo].[114sct_find_fault]", conn);
            adapter = new SqlDataAdapter(cmd);
            data = new DataSet();
            try
            {
                conn.Open();
                adapter.Fill(data, "114sct_find_fault");
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            datagrid.Columns.Clear();
            datagrid.DataSource = data;
            TemplateField check = new TemplateField();
            check.ItemTemplate = new GridViewTemplate_CheckBox();
            check.ItemStyle.Width = new Unit(30, UnitType.Pixel);
            //check.ControlStyle.Width = new Unit(5, UnitType.Pixel);
            datagrid.Columns.Add(check);
            BoundField id = new BoundField();
            id.DataField = "id";
            id.HeaderText = "ID";
            id.ReadOnly = true;
            id.SortExpression = "id";
            id.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            //id.ControlStyle.Width = new Unit(30, UnitType.Pixel);
            datagrid.Columns.Add(id);
            BoundField fault = new BoundField();
            fault.DataField = "fault";
            fault.HeaderText = "挑错";
            fault.ReadOnly = true;
            fault.SortExpression = "fault";
            fault.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            //fault.ControlStyle.Width = new Unit(30, UnitType.Pixel);
            datagrid.Columns.Add(fault);
            //datagrid.RowDataBound += Fault_RowDataBound;
            datagrid.DataKeyNames = new string[] { "id" };
            datagrid.RowDataBound += FaultManage_RowDataBound;
            datagrid.DataBind();
            delfaultbtn.Visible = true;
            string str = "";
            for (int i = 0; i < datagrid.Rows.Count; i++)
            {
                str += "checkedlist[" + i.ToString() + "]='" + datagrid.Rows[i].Cells[0].Controls[0].ID.ToString() + "';";
            }
            ClientScript.RegisterStartupScript(this.GetType(), "init", "<script>var checkedlist=new Array();" + str + "delconfirm=undefined;</script>");
            ClientScript.RegisterOnSubmitStatement(this.GetType(), "onsubmit", "if(delconfirm==false){return false;};" +
                                                                                "for(var i=0;i<checkedlist.length;i++)" +
                                                                                "{if(document.getElementById(checkedlist[i]).checked==true) document.getElementById('checkedlist').value+=(checkedlist[i]+'|')}");
            delfaultbtn.OnClientClick = "javascript:var r=confirm('确实要删除吗？');if(r==true){delconfirm=true;}else{delconfirm=false;}";
        }

        protected void FaultManage_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ((CheckBox)e.Row.Cells[0].Controls[0]).ID = ((DataRowView)e.Row.DataItem)["id"].ToString();
            }
        }

        protected void DelFault(object sender, EventArgs e)
        {
            string checkedlist = Request.Params["checkedlist"];
            if (checkedlist == "")
            {
                ClientScript.RegisterStartupScript(this.GetType(), "delerror", "<script>alert('删除前请选择')</script>");
                FaultManage(null, EventArgs.Empty);
                return;
            }
            char[] charSeparators = new char[] { '|' };
            string[] faults = checkedlist.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
            SqlConnection conn = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("delete from [114sct_find_fault] where [id]=@id", conn);
            cmd.Parameters.Add("@id", SqlDbType.Int);
            try
            {
                conn.Open();
                foreach (string fault in faults)
                {
                    cmd.Parameters["@id"].Value = Convert.ToInt32(fault);
                    cmd.ExecuteNonQuery();
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            FaultManage(null, EventArgs.Empty);
        }
        protected void AdviceManage(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("select * from [dbo].[114sct_advice]", conn);
            adapter = new SqlDataAdapter(cmd);
            data = new DataSet();
            try
            {
                conn.Open();
                adapter.Fill(data, "114sct_advice");
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            datagrid.Columns.Clear();
            datagrid.DataSource = data;
            TemplateField check = new TemplateField();
            check.ItemTemplate = new GridViewTemplate_CheckBox();
            check.ItemStyle.Width = new Unit(30, UnitType.Pixel);
            datagrid.Columns.Add(check);
            BoundField id = new BoundField();
            id.DataField = "id";
            id.HeaderText = "ID";
            id.ReadOnly = true;
            id.SortExpression = "id";
            id.ItemStyle.Width = new Unit(30, UnitType.Pixel);
            datagrid.Columns.Add(id);
            BoundField problem = new BoundField();
            problem.DataField = "problem";
            problem.HeaderText = "问题类型";
            problem.ReadOnly = true;
            problem.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(problem);
            BoundField description = new BoundField();
            description.DataField = "description";
            description.HeaderText = "问题描述";
            description.ReadOnly = true;
            description.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(description);
            BoundField name = new BoundField();
            name.DataField = "name";
            name.HeaderText = "称呼";
            name.ReadOnly = true;
            name.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(name);
            BoundField contact = new BoundField();
            contact.DataField = "contact";
            contact.HeaderText = "联系方式";
            contact.ReadOnly = true;
            contact.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(contact);
            datagrid.RowDataBound+=AdviceManage_RowDataBound;
            datagrid.DataKeyNames = new string[] { "id" };
            datagrid.DataBind();
            string str = "";
            for (int i = 0; i < datagrid.Rows.Count; i++)
            {
                str += "checkedlist[" + i.ToString() + "]='" + datagrid.Rows[i].Cells[0].Controls[0].ID.ToString() + "';";
            }
            ClientScript.RegisterStartupScript(this.GetType(), "init", "<script>var checkedlist=new Array();" + str + "delconfirm=undefined;</script>");
            ClientScript.RegisterOnSubmitStatement(this.GetType(), "onsubmit", "if(delconfirm==false){return false;};" +
                                                                                "for(var i=0;i<checkedlist.length;i++)" +
                                                                                "{if(document.getElementById(checkedlist[i]).checked==true) document.getElementById('checkedlist').value+=(checkedlist[i]+'|')}");
            deladvicebtn.Visible = true;
            deladvicebtn.OnClientClick = "javascript:var r=confirm('确实要删除吗？');if(r==true){delconfirm=true;}else{delconfirm=false;}";
        }

        protected void AdviceManage_RowDataBound(object sender,GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ((CheckBox)e.Row.Cells[0].Controls[0]).ID = ((DataRowView)e.Row.DataItem)["id"].ToString();
            }
        }
        protected void DelAdvice(object sender, EventArgs e)
        {
            string checkedlist = Request.Params["checkedlist"];
            if (checkedlist == "")
            {
                ClientScript.RegisterStartupScript(this.GetType(), "delerror", "<script>alert('删除前请选择')</script>");
                AdviceManage(null, EventArgs.Empty);
                return;
            }
            char[] charSeparators = new char[] { '|' };
            string[] advices = checkedlist.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
            SqlConnection conn = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("delete from [114sct_advice] where [id]=@id", conn);
            cmd.Parameters.Add("@id", SqlDbType.Int);
            try
            {
                conn.Open();
                foreach (string advice in advices)
                {
                    cmd.Parameters["@id"].Value = Convert.ToInt32(advice);
                    cmd.ExecuteNonQuery();
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            AdviceManage(null, EventArgs.Empty);
        }
        protected void cjManage(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("select * from [dbo].[cj]", conn);
            adapter = new SqlDataAdapter(cmd);
            data = new DataSet();
            try
            {
                conn.Open();
                adapter.Fill(data, "cj");
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            datagrid.Columns.Clear();
            datagrid.DataSource = data;
            TemplateField check = new TemplateField();
            check.ItemTemplate = new GridViewTemplate_CheckBox();
            check.ItemStyle.Width = new Unit(30, UnitType.Pixel);
            datagrid.Columns.Add(check);
            //BoundField round = new BoundField();
            //round.DataField = "round";
            //round.HeaderText = "期数";
            //round.ReadOnly = true;
            //round.SortExpression = "round";
            //round.ItemStyle.Width = new Unit(30, UnitType.Pixel);
            //datagrid.Columns.Add(round);
            TemplateField round = new TemplateField();
            round.ItemTemplate = new GridViewTemplate_Label();
            round.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            round.FooterTemplate = new GridViewTemplate_TextBox("round");
            round.HeaderText = "期数";
            datagrid.Columns.Add(round);
            BoundField personnum = new BoundField();
            personnum.DataField = "personnum";
            personnum.HeaderText = "参与人数";
            personnum.ReadOnly = true;
            personnum.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(personnum);
            BoundField luckynum = new BoundField();
            luckynum.DataField = "luckynum";
            luckynum.HeaderText = "中奖号码";
            luckynum.ReadOnly = true;
            luckynum.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(luckynum);
            //BoundField closetime = new BoundField();
            //closetime.DataField = "closetime";
            //closetime.HeaderText = "结束时间";
            //closetime.ReadOnly = true;
            TemplateField closetime = new TemplateField();
            closetime.ItemTemplate = new GridViewTemplate_Label();
            closetime.ItemStyle.Width = new Unit(300, UnitType.Pixel);
            closetime.FooterTemplate = new GridViewTemplate_TextBox("closetime");
            closetime.HeaderText = "结束时间";
            datagrid.Columns.Add(closetime);

            datagrid.DataKeyNames = new string[] { "round" };
            datagrid.ShowFooter = true;
            datagrid.RowDataBound += cjManage_RowDataBound;
            datagrid.DataBind();
            string str="";
            for(int i=0;i<datagrid.Rows.Count;i++)
            {
                str+="checkedlist["+i.ToString()+"]='"+datagrid.Rows[i].Cells[0].Controls[0].ID.ToString()+"';";
            }
            ClientScript.RegisterStartupScript(this.GetType(),"init","<script>var checkedlist=new Array();"+str+"delconfirm=undefined;</script>");
            ClientScript.RegisterOnSubmitStatement(this.GetType(), "onsubmit", "if(delconfirm==false){return false;};"+
                                                                                "document.getElementById('newround').value=document.getElementById('round').value;"+
                                                                                "document.getElementById('newclosetime').value=document.getElementById('closetime').value;"+
                                                                                "for(var i=0;i<checkedlist.length;i++)"+
                                                                                "{if(document.getElementById(checkedlist[i]).checked==true) document.getElementById('checkedlist').value+=(checkedlist[i]+'|')}");
            addbtn.Visible = true;
            delbtn.Visible = true;
            detailbtn.Visible = true;
            delbtn.OnClientClick = "javascript:var r=confirm('确实要删除吗？');if(r==true){delconfirm=true;}else{delconfirm=false;}";
        }

        protected void AddRound(object sender, EventArgs e)
        {

            string round = Request.Form["newround"];
            string closetime = Request.Form["newclosetime"];
            if(string.IsNullOrEmpty(round)||(string.IsNullOrEmpty(closetime)))
            {
                ClientScript.RegisterStartupScript(this.GetType(),"adderror","<script>alert('期数和结束时间不能为空');</script>");
                cjManage(null, EventArgs.Empty);
                return;
            }
            SqlConnection conn = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("insert into [cj] (round,personnum,luckynum,closetime) values(@round,0,0,@closetime)", conn);
            cmd.Parameters.Add("@round", SqlDbType.Int).Value = Convert.ToInt32(round);
            cmd.Parameters.Add("@closetime", SqlDbType.DateTime).Value = Convert.ToDateTime(closetime);
            try
            {
                conn.Open();
                cmd.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            cjManage(null, EventArgs.Empty);
        }

        protected void DelRound(object sender, EventArgs e)
        {
            string checkedlist = Request.Params["checkedlist"];
            if (checkedlist == "")
            {
                ClientScript.RegisterStartupScript(this.GetType(), "delerror", "<script>alert('删除前请选择')</script>");
                cjManage(null, EventArgs.Empty);
                return;
            }
            char[] charSeparators = new char[] { '|' };
            string[] rounds = checkedlist.Split(charSeparators,StringSplitOptions.RemoveEmptyEntries);
            SqlConnection conn = new SqlConnection(connectionString);
            SqlCommand cmd1=new SqlCommand();
            cmd1.CommandText="delete from [cj] where [round]=@round";
            cmd1.Connection=conn;
            cmd1.Parameters.Add("@round", SqlDbType.Int);
            SqlCommand cmd2=new SqlCommand("delete from [cjz] where [round]=@round",conn);
            cmd2.Parameters.Add("@round", SqlDbType.Int);
            try
            {
                conn.Open();
                foreach (string round in rounds)
                {

                    cmd1.Parameters["@round"].Value = Convert.ToInt32(round);
                    cmd1.ExecuteNonQuery();
                    cmd2.Parameters["@round"].Value = Convert.ToInt32(round);
                    cmd2.ExecuteNonQuery();
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            cjManage(null, EventArgs.Empty);
        }

        protected void DetailRound(object sender, EventArgs e)
        {
            string checkedlist = Request.Params["checkedlist"];
            if (checkedlist == "")
            {
                ClientScript.RegisterStartupScript(this.GetType(), "detailerror", "<script>alert('请选择一期活动')</script>");
                cjManage(null, EventArgs.Empty);
                return;
            }
            if(checkedlist.Length>2)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "detailerror", "<script>alert('只能选择一期')</script>");
                cjManage(null, EventArgs.Empty);
                return;
            }
            char[] charSeparators = new char[] { '|' };
            string[] rounds = checkedlist.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
            SqlConnection conn = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("select * from [cjz] where [round]=@round", conn);
            cmd.Parameters.Add("@round", SqlDbType.Int).Value = Convert.ToInt32(rounds[0]);
            adapter=new SqlDataAdapter(cmd);
            data=new DataSet();
            try
            {
                conn.Open();
                adapter.Fill(data, "cjz");
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            datagrid.Columns.Clear();
            datagrid.DataSource = data;
            BoundField telephone = new BoundField();
            telephone.DataField = "telephone";
            telephone.HeaderText = "手机";
            telephone.ReadOnly = true;
            telephone.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(telephone);
            BoundField ip = new BoundField();
            ip.DataField = "ip";
            ip.HeaderText = "ip";
            ip.ReadOnly = true;
            ip.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(ip);
            BoundField name = new BoundField();
            name.DataField = "name";
            name.HeaderText = "名字";
            name.ReadOnly = true;
            name.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(name);
            BoundField luckynum = new BoundField();
            luckynum.DataField = "luckynum";
            luckynum.HeaderText = "抽奖号码";
            luckynum.ReadOnly = true;
            luckynum.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(luckynum);
            BoundField time = new BoundField();
            time.DataField = "time";
            time.HeaderText = "时间";
            time.ReadOnly = true;
            time.ItemStyle.Width = new Unit(100, UnitType.Pixel);
            datagrid.Columns.Add(time);
            datagrid.DataBind();
            addbtn.Visible = false;
            delbtn.Visible = false;
            detailbtn.Visible = false;
            returnbtn.Visible = true;
        }
        protected void cjManage_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //if (e.Row.RowType == DataControlRowType.Footer)
            //{
            //    //e.Row.Cells[4].Controls.Add(btn);
               
            //    //((Button)e.Row.Cells[4].Controls[1]).Click += new EventHandler(AddRound);
            //}
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ((Label)e.Row.Cells[1].Controls[0]).Text = ((DataRowView)e.Row.DataItem)["round"].ToString();
                ((Label)e.Row.Cells[4].Controls[0]).Text = ((DataRowView)e.Row.DataItem)["closetime"].ToString();
                ((CheckBox)e.Row.Cells[0].Controls[0]).ID = ((DataRowView)e.Row.DataItem)["round"].ToString();
            }
        }
    }


    public class GridViewTemplate_CheckBox : ITemplate
    {
        void ITemplate.InstantiateIn(System.Web.UI.Control container)
        {
            CheckBox checkbox = new CheckBox();
            //checkbox.ID = "checkbox";
            checkbox.ClientIDMode = ClientIDMode.Static;
            container.Controls.Add(checkbox);
        }
    }

    public class GridViewTemplate_ImageLink : ITemplate
    {
        void ITemplate.InstantiateIn(System.Web.UI.Control container)
        {
            HyperLink link = new HyperLink();
            link.Text = "证件";
            container.Controls.Add(link);
        }
    }

    public class GridViewTemplate_Label : ITemplate
    {
        void ITemplate.InstantiateIn(System.Web.UI.Control container)
        {
            Label la = new Label();
            container.Controls.Add(la);
        }
    }
    public class GridViewTemplate_TextBox : ITemplate
    {
        private string ParamName;
        public GridViewTemplate_TextBox(string paramname)
        {
            ParamName = paramname;
        }
        void ITemplate.InstantiateIn(System.Web.UI.Control container)
        {
            TextBox tb=new TextBox();
            tb.ID=ParamName;
            tb.ClientIDMode = ClientIDMode.Static;
            container.Controls.Add(tb);
        }
    }
    //public class GridViewTemplate_TextBox_Button : ITemplate
    //{
    //    void ITemplate.InstantiateIn(System.Web.UI.Control container)
    //    {
    //        TextBox tb = new TextBox();
    //        container.Controls.Add(tb);
            
    //        container.Controls.Add(btn);
    //    }
    //}
}